package hongcaosp.app.android.login;

import hongcaosp.app.android.modle.BaseResponse;
import hongcaosp.app.android.modle.DataCallBack;
import hongcaosp.app.android.modle.impl.LoginModleImpl;
import hongcaosp.app.android.modle.impl.PasswordModleImpl;
import hongcaosp.app.android.modle.mi.LoginModle;
import hongcaosp.app.android.modle.mi.PasswordModle;
import xlj.lib.android.base.component.BasePresenter;
import xlj.lib.android.base.toastcompat.ToastManager;

public class RegisterPresenter extends BasePresenter {
    private ICodeView codeView;
    private IRegisterView registerView;
    private PasswordModle passwordModle;
    private LoginModle loginModle;

    public RegisterPresenter(ICodeView codeView,IRegisterView registerView) {
        this.codeView = codeView;
        this.registerView = registerView;
        loginModle = new LoginModleImpl();
        passwordModle = new PasswordModleImpl();
    }

    public void sendCode(String mobile) {
        passwordModle.sendCode(mobile, 5, new DataCallBack() {
            @Override
            public void onGetData(Object data) {
                super.onGetData(data);
                codeView.onCodeSend(true);
            }

            @Override
            public void onFail(int code, String errorMessage) {
                super.onFail(code, errorMessage);
                codeView.onCodeSend(false);
                ToastManager.getInstance().showToast(errorMessage);
            }
        });
    }

    public void register(String phone,String code,String invite) {
        loginModle.register(phone, code, invite, new DataCallBack<BaseResponse>() {
            @Override
            public void onGetData(BaseResponse data) {
                super.onGetData(data);
                registerView.onRegister(true,"注册成功");
            }

            @Override
            public void onFail(int code, String errorMessage) {
                super.onFail(code, errorMessage);
                ToastManager.getInstance().showToast(errorMessage);
            }
        });
    }
}
